package com.ztgf.sys.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.sys.models.service.ISysHelpService;
import com.ztgf.sys.models.bo.SysHelpBO;
import com.ztgf.sys.models.dto.SysHelpDTO;

/**
 * '制度表（帮助说明）
 *
 * @author YUE
 * @Date 2020-05-27 14:54:01
 */

@RestController
@RequestMapping("/api/sysHelp")
@Slf4j
@Api(value = "SysHelpApiController",tags = "'制度表（帮助说明）")
public class SysHelpApiController {

    @DubboReference
    private ISysHelpService sysHelpService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<SysHelpDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        SysHelpDTO dto = sysHelpService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "'制度表（帮助说明）列表",notes = "'制度表（帮助说明）列表")
    @PostMapping("/queryPageList")
    public Result<Page<SysHelpDTO>> queryPageList(SysHelpBO bo){
       Wrapper<SysHelpDTO> wrapper = new EntityWrapper<>();
        if (bo.getStartDate() != null){
            wrapper.ge("create_time", bo.getStartDate());
        }
        if (bo.getEndDate() != null){
            wrapper.le("create_time", bo.getEndDate());

        }
        Page<SysHelpDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = sysHelpService.selectPage(page, wrapper);

        return new Result<>(page);
    }
}
